package com.example.lyl.testpermission.testpermissiontwo;


import android.Manifest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.lyl.testpermission.R;
import com.example.lyl.testpermission.testpermissiontwo.util.MPermissionUtils;

/**
 * Created by lyl on 2017/3/3.
 */

public class ReqestPermissionActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_request);
    }

    public void callPhone(View view){
        MPermissionUtils.requestPermissionsResult(this, 1, new String[]{Manifest.permission.CALL_PHONE}
                , new MPermissionUtils.OnPermissionListener() {
                    //Granted 授予 同意
                    @Override
                    public void onPermissionGranted() {
                        Toast.makeText(ReqestPermissionActivity.this, "授权成功,执行拨打电话操作!", Toast.LENGTH_SHORT).show();
                    }
                    //Denied 拒绝 拒签
                    @Override
                    public void onPermissionDenied() {
                        MPermissionUtils.showTipsDialog(ReqestPermissionActivity.this);
                    }
                });
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        MPermissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}